<?php
/**
 * 重庆柯一网络有限公司
 * 遵循MT协议，开源并可商业使用，没有任何限制
 * @Author:cqkyi
 * @Date: 2020/8/14 13:44
 * 官方惟一地址：www.cqkyi.com
 */

namespace app\apiadmin\middleware;


use app\common\utils\Res;

use app\common\service\JwtService;
class CheckToken
{



    public function handle($request, \Closure $next)
    {
        $token = $request->header('token');
        if(empty($token)){
            return  Res::error(201,"非法操作");
        }
        $result = JwtService::checkToken($token);
        if($result['code']!=200){
           return Res::arrError($result);
        }
        $request->userInfo = $result;
        $request->username = $result['data']->username;
        $request->user_id = $result['data']->user_id;
        $request->avatar = $result['data']->avatar;

        return $next($request);
    }


}